package com.tx.freemarker.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ：tx
 * @description：
 * @date ：Created in 2019/8/10 14:38
 * @modified By：
 * @version:
 */
@Controller
public class HelloController {

    @GetMapping("/hello")
    public String helloWorld(Model model){
        Map<String,Object> map = new HashMap<>();
        map.put("name","mercury");
        model.addAttribute("hello",map);
        return "hello";
    }

    /**
     * 指令
     * @param model
     * @return
     */
    @GetMapping("/expression")
    public String expression(Model model){
        Map<String,Object> map = new HashMap<>();
        map.put("name","mercury");
        model.addAttribute("hello",map);
        model.addAttribute("people","hahaha");
        return "expression";
    }


    /**
     * 插值
     * @param model
     * @return
     */
    @GetMapping("/insertVal")
    public String insertVal(Model model){
        model.addAttribute("people","hahaha");
        model.addAttribute("mercuryDate",new Date());
        model.addAttribute("mercuryBoolean",true);
        return "insertValue";
    }

    /**
     * 自定义指令
     * @param model
     * @return
     */
    @GetMapping("/customerInstruction")
    public String customerInstruction(Model model){
        model.addAttribute("people","hahaha");
        model.addAttribute("mercuryDate",new Date());
        model.addAttribute("mercuryBoolean",true);
        return "customerInstruction";
    }

    /**
     * 命名空间
     * @param model
     * @return
     */
    @GetMapping("/namespace")
    public String namespace(Model model){
        return "importNamespace";
    }
}
